﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_teacher
	/// </summary>
	public partial class oa_teacher
	{
		public oa_teacher()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("person_id", "oa_teacher"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int person_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_teacher");
			strSql.Append(" where person_id=@person_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11)};
			parameters[0].Value = person_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_teacher model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_teacher(");
			strSql.Append("person_id,learn_code,birthday,degree_code,polity_code,marry_state,graduate_college,work_date,position,professional,mobile_tel,home_tel,e_mail,home_address,link_address,introduce,team_id,if_leader)");
			strSql.Append(" values (");
			strSql.Append("@person_id,@learn_code,@birthday,@degree_code,@polity_code,@marry_state,@graduate_college,@work_date,@position,@professional,@mobile_tel,@home_tel,@e_mail,@home_address,@link_address,@introduce,@team_id,@if_leader)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11),
					new MySqlParameter("@learn_code", MySqlDbType.VarChar,32),
					new MySqlParameter("@birthday", MySqlDbType.DateTime),
					new MySqlParameter("@degree_code", MySqlDbType.Int32,11),
					new MySqlParameter("@polity_code", MySqlDbType.Int32,11),
					new MySqlParameter("@marry_state", MySqlDbType.Int32,11),
					new MySqlParameter("@graduate_college", MySqlDbType.VarChar,256),
					new MySqlParameter("@work_date", MySqlDbType.DateTime),
					new MySqlParameter("@position", MySqlDbType.VarChar,64),
					new MySqlParameter("@professional", MySqlDbType.Int32,11),
					new MySqlParameter("@mobile_tel", MySqlDbType.VarChar,32),
					new MySqlParameter("@home_tel", MySqlDbType.VarChar,32),
					new MySqlParameter("@e_mail", MySqlDbType.VarChar,32),
					new MySqlParameter("@home_address", MySqlDbType.VarChar,256),
					new MySqlParameter("@link_address", MySqlDbType.VarChar,256),
					new MySqlParameter("@introduce", MySqlDbType.VarChar,256),
					new MySqlParameter("@team_id", MySqlDbType.Int32,11),
					new MySqlParameter("@if_leader", MySqlDbType.Int32,11)};
			parameters[0].Value = model.person_id;
			parameters[1].Value = model.learn_code;
			parameters[2].Value = model.birthday;
			parameters[3].Value = model.degree_code;
			parameters[4].Value = model.polity_code;
			parameters[5].Value = model.marry_state;
			parameters[6].Value = model.graduate_college;
			parameters[7].Value = model.work_date;
			parameters[8].Value = model.position;
			parameters[9].Value = model.professional;
			parameters[10].Value = model.mobile_tel;
			parameters[11].Value = model.home_tel;
			parameters[12].Value = model.e_mail;
			parameters[13].Value = model.home_address;
			parameters[14].Value = model.link_address;
			parameters[15].Value = model.introduce;
			parameters[16].Value = model.team_id;
			parameters[17].Value = model.if_leader;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_teacher model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_teacher set ");
			strSql.Append("learn_code=@learn_code,");
			strSql.Append("birthday=@birthday,");
			strSql.Append("degree_code=@degree_code,");
			strSql.Append("polity_code=@polity_code,");
			strSql.Append("marry_state=@marry_state,");
			strSql.Append("graduate_college=@graduate_college,");
			strSql.Append("work_date=@work_date,");
			strSql.Append("position=@position,");
			strSql.Append("professional=@professional,");
			strSql.Append("mobile_tel=@mobile_tel,");
			strSql.Append("home_tel=@home_tel,");
			strSql.Append("e_mail=@e_mail,");
			strSql.Append("home_address=@home_address,");
			strSql.Append("link_address=@link_address,");
			strSql.Append("introduce=@introduce,");
			strSql.Append("team_id=@team_id,");
			strSql.Append("if_leader=@if_leader");
			strSql.Append(" where person_id=@person_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@learn_code", MySqlDbType.VarChar,32),
					new MySqlParameter("@birthday", MySqlDbType.DateTime),
					new MySqlParameter("@degree_code", MySqlDbType.Int32,11),
					new MySqlParameter("@polity_code", MySqlDbType.Int32,11),
					new MySqlParameter("@marry_state", MySqlDbType.Int32,11),
					new MySqlParameter("@graduate_college", MySqlDbType.VarChar,256),
					new MySqlParameter("@work_date", MySqlDbType.DateTime),
					new MySqlParameter("@position", MySqlDbType.VarChar,64),
					new MySqlParameter("@professional", MySqlDbType.Int32,11),
					new MySqlParameter("@mobile_tel", MySqlDbType.VarChar,32),
					new MySqlParameter("@home_tel", MySqlDbType.VarChar,32),
					new MySqlParameter("@e_mail", MySqlDbType.VarChar,32),
					new MySqlParameter("@home_address", MySqlDbType.VarChar,256),
					new MySqlParameter("@link_address", MySqlDbType.VarChar,256),
					new MySqlParameter("@introduce", MySqlDbType.VarChar,256),
					new MySqlParameter("@team_id", MySqlDbType.Int32,11),
					new MySqlParameter("@if_leader", MySqlDbType.Int32,11),
					new MySqlParameter("@person_id", MySqlDbType.Int32,11)};
			parameters[0].Value = model.learn_code;
			parameters[1].Value = model.birthday;
			parameters[2].Value = model.degree_code;
			parameters[3].Value = model.polity_code;
			parameters[4].Value = model.marry_state;
			parameters[5].Value = model.graduate_college;
			parameters[6].Value = model.work_date;
			parameters[7].Value = model.position;
			parameters[8].Value = model.professional;
			parameters[9].Value = model.mobile_tel;
			parameters[10].Value = model.home_tel;
			parameters[11].Value = model.e_mail;
			parameters[12].Value = model.home_address;
			parameters[13].Value = model.link_address;
			parameters[14].Value = model.introduce;
			parameters[15].Value = model.team_id;
			parameters[16].Value = model.if_leader;
			parameters[17].Value = model.person_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int person_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_teacher ");
			strSql.Append(" where person_id=@person_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11)};
			parameters[0].Value = person_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string person_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_teacher ");
			strSql.Append(" where person_id in ("+person_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_teacher GetModel(int person_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select person_id,learn_code,birthday,degree_code,polity_code,marry_state,graduate_college,work_date,position,professional,mobile_tel,home_tel,e_mail,home_address,link_address,introduce,team_id,if_leader from oa_teacher ");
			strSql.Append(" where person_id=@person_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@person_id", MySqlDbType.Int32,11)};
			parameters[0].Value = person_id;

			becom.Model.oa_teacher model=new becom.Model.oa_teacher();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["person_id"]!=null && ds.Tables[0].Rows[0]["person_id"].ToString()!="")
				{
					model.person_id=int.Parse(ds.Tables[0].Rows[0]["person_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["learn_code"]!=null && ds.Tables[0].Rows[0]["learn_code"].ToString()!="")
				{
					model.learn_code=ds.Tables[0].Rows[0]["learn_code"].ToString();
				}
				if(ds.Tables[0].Rows[0]["birthday"]!=null && ds.Tables[0].Rows[0]["birthday"].ToString()!="")
				{
					model.birthday=DateTime.Parse(ds.Tables[0].Rows[0]["birthday"].ToString());
				}
				if(ds.Tables[0].Rows[0]["degree_code"]!=null && ds.Tables[0].Rows[0]["degree_code"].ToString()!="")
				{
					model.degree_code=int.Parse(ds.Tables[0].Rows[0]["degree_code"].ToString());
				}
				if(ds.Tables[0].Rows[0]["polity_code"]!=null && ds.Tables[0].Rows[0]["polity_code"].ToString()!="")
				{
					model.polity_code=int.Parse(ds.Tables[0].Rows[0]["polity_code"].ToString());
				}
				if(ds.Tables[0].Rows[0]["marry_state"]!=null && ds.Tables[0].Rows[0]["marry_state"].ToString()!="")
				{
					model.marry_state=int.Parse(ds.Tables[0].Rows[0]["marry_state"].ToString());
				}
				if(ds.Tables[0].Rows[0]["graduate_college"]!=null && ds.Tables[0].Rows[0]["graduate_college"].ToString()!="")
				{
					model.graduate_college=ds.Tables[0].Rows[0]["graduate_college"].ToString();
				}
				if(ds.Tables[0].Rows[0]["work_date"]!=null && ds.Tables[0].Rows[0]["work_date"].ToString()!="")
				{
					model.work_date=DateTime.Parse(ds.Tables[0].Rows[0]["work_date"].ToString());
				}
				if(ds.Tables[0].Rows[0]["position"]!=null && ds.Tables[0].Rows[0]["position"].ToString()!="")
				{
					model.position=ds.Tables[0].Rows[0]["position"].ToString();
				}
				if(ds.Tables[0].Rows[0]["professional"]!=null && ds.Tables[0].Rows[0]["professional"].ToString()!="")
				{
					model.professional=int.Parse(ds.Tables[0].Rows[0]["professional"].ToString());
				}
				if(ds.Tables[0].Rows[0]["mobile_tel"]!=null && ds.Tables[0].Rows[0]["mobile_tel"].ToString()!="")
				{
					model.mobile_tel=ds.Tables[0].Rows[0]["mobile_tel"].ToString();
				}
				if(ds.Tables[0].Rows[0]["home_tel"]!=null && ds.Tables[0].Rows[0]["home_tel"].ToString()!="")
				{
					model.home_tel=ds.Tables[0].Rows[0]["home_tel"].ToString();
				}
				if(ds.Tables[0].Rows[0]["e_mail"]!=null && ds.Tables[0].Rows[0]["e_mail"].ToString()!="")
				{
					model.e_mail=ds.Tables[0].Rows[0]["e_mail"].ToString();
				}
				if(ds.Tables[0].Rows[0]["home_address"]!=null && ds.Tables[0].Rows[0]["home_address"].ToString()!="")
				{
					model.home_address=ds.Tables[0].Rows[0]["home_address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["link_address"]!=null && ds.Tables[0].Rows[0]["link_address"].ToString()!="")
				{
					model.link_address=ds.Tables[0].Rows[0]["link_address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["introduce"]!=null && ds.Tables[0].Rows[0]["introduce"].ToString()!="")
				{
					model.introduce=ds.Tables[0].Rows[0]["introduce"].ToString();
				}
				if(ds.Tables[0].Rows[0]["team_id"]!=null && ds.Tables[0].Rows[0]["team_id"].ToString()!="")
				{
					model.team_id=int.Parse(ds.Tables[0].Rows[0]["team_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["if_leader"]!=null && ds.Tables[0].Rows[0]["if_leader"].ToString()!="")
				{
					model.if_leader=int.Parse(ds.Tables[0].Rows[0]["if_leader"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select person_id,learn_code,birthday,degree_code,polity_code,marry_state,graduate_college,work_date,position,professional,mobile_tel,home_tel,e_mail,home_address,link_address,introduce,team_id,if_leader ");
			strSql.Append(" FROM oa_teacher ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_teacher";
			parameters[1].Value = "person_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

